package routers

import (
	_ "github.com/EDDYCJY/go-gin-app/docs"
	"github.com/EDDYCJY/go-gin-app/middleware/jwt"
	"github.com/EDDYCJY/go-gin-app/pkg/setting"
	"github.com/EDDYCJY/go-gin-app/routers/api"
	v1 "github.com/EDDYCJY/go-gin-app/routers/api/v1"
	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
)

func InitRouter() *gin.Engine  {
	r := gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	gin.SetMode(setting.ServerSetting.RunMode)
	r.GET("/test", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "test",
		})
	})
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	r.GET("/getToken", api.GetToken)
	r.POST("/upload", api.UploadImage).Use(jwt.JWT())
	apiV1 := r.Group("/api/v1")
	apiV1.Use(jwt.JWT())
	{
		//标签
		apiV1.GET("/tags", v1.GetTags)
		apiV1.POST("/tags", v1.AddTag)
		apiV1.PUT("/tags/:id", v1.EditTag)
		apiV1.DELETE("/tags/:id", v1.DeleteTag)

		//文章
		apiV1.GET("/articles", v1.GetArticles)
		apiV1.GET("/article/:id", v1.GetArticle)
		apiV1.POST("/articles", v1.AddArticle)
		apiV1.PUT("/articles/:id", v1.EditArticle)
		apiV1.DELETE("/articles/:id", v1.DeleteArticle)
	}
	return r
}
